<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style>
			#msg {
				margin: 50px;
				font-size: 35px;
			}

			.btnstyle {
				margin: 0px 0px 0px 50px;
			}
		</style>
	</head>
	<body>
		<div id="msg">0</div>
		<div class="btnstyle">
			<button id="btnStart" onclick="start();">开始计时</button>
			<button id="btnStop" onclick="stop();">结束计时</button>
		</div>
	</body>

	<script>
		var count = 0;
		var timer; //创建定时器
		var clickStart = 1; //是否开始
		var msg = document.getElementById("msg");
		var btnStart = document.getElementById("btnStart");
		//点击开始，计时定时刷新 按钮名称：
		function start() {
			if (clickStart % 2 != 0) {
				timer = setInterval(function() {
					count = count + 1;
					msg.innerText = count;
				}, 10)

				clickStart++;
				btnStart.innerText = "暂停计时";
			} else {
				clearInterval(timer);
				clickStart = 1;
				btnStart.innerText = "开始计时";
			}
	}

		function stop() {
			count = 0;
			msg.innerText=count;
			clearInterval(timer);
			btnStart.innerText = "开始计时";


		}
	</script>
</html>
